package com.newcapec.lesson2;

import com.newcapec.lesson1.Person;

public class Driver extends Person {

    private Car car;

    public Driver() {
    }

    public Driver(String name, String sex, int age) {
        super(name, sex, age);
    }

    public Driver(String name, String sex, int age, Car car) {
        super(name, sex, age);
        this.car = car;
    }

    public Driver(Driver driver){
        super(driver);
        this.car = driver.car;

    }

    public Car getCar() {
        return car;
    }

    @Override
    public boolean equals(Object o) {
        // == 比较的是字面量
        if (this == o) {
            return true;
        }
        //此时地址不一样，需要查看内容是否一致
        if (o instanceof Driver) {
            //判断具体内容
            Driver driver = (Driver) o;
            if(super.equals(driver) &&
                    this.car.equals(driver.getCar())){
                return true;
            }
        }

        return false;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public String toString() {
        return "Driver{" + super.toString()+
                "car=" + car +
                '}';
    }
}
